package org.lanzier.common.utils;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

/**
 * @author lansb
 * xml操作
 */
public class XmlUtils {
	/**
	 * 根据xml字符串获得NodeList列表
	 *@param xml
	 *@return
	 *@throws ParserConfigurationException  
	 * @throws IOException 
	 * @throws SAXException 
	 * @throws UnsupportedEncodingException 
	 */
	public static NodeList getNoteListByString(String xml) throws ParserConfigurationException, UnsupportedEncodingException, SAXException, IOException {
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
		DocumentBuilder docb = factory.newDocumentBuilder();
		Document doc = docb.parse(new ByteArrayInputStream(xml
				.getBytes(Environment.ENCODING)));
		Element root = doc.getDocumentElement();
		NodeList sqlNodes = root.getChildNodes();
		return sqlNodes;
	}
}
